<template>
  <div>
    <el-form ref="form" label-width="100px" :model="form" :rules="formRules">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title" placeholder="请输入标题" />
      </el-form-item>
      <el-form-item label="类型">
        <el-radio-group v-model="form.type">
          <el-radio :label="1" border>动态</el-radio>
          <!--<el-radio :label="2" border>招生简章</el-radio>-->
        </el-radio-group>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <tinymce v-model="form.content" :height="500" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { create } from '../../api/moment'
import tinymce from '@/components/Tinymce'
export default {
  components: {
    tinymce: tinymce
  },
  data() {
    return {
      form: {
        title: '',
        type: 1,
        content: ''
      },
      formRules: {
        title: [
          { required: true, message: '请输入标题' }
        ],
        content: [
          { required: true, message: '请填写内容' }
        ]
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          const data = Object.assign({
            status: 1
          }, this.form)
          create(data).then(() => {
            this.$router.push({
              name: 'moment-index'
            })
          })
        } else {
          console.log('fail')
          return false
        }
      })
    }
  }
}
</script>

<style>
</style>
